package com.wjf.birdfish.hibernate;

import java.util.ArrayList;
import java.util.List;

public class PageImpl<T> extends AbstractPage<T> implements Page<T> {
	private List<T> source = new ArrayList<T>();
	
	public PageImpl(List<T> data, int pageSize) {
		this.source = data;
		this.recordNumber = this.source.size();
		this.pageSize = pageSize;
		setPageNumber();
	}
	
	public List<T> getData() {
		if(getPageSize() <= 0 ){
			return source;
		}
		if (data == null) {
			int start = computeFirstResult();
			if(start >= this.source.size()){
				start = this.source.size() -1;
			}
			int end = start + getPageSize();
			// modify by liwei on 2011/04/08
			/*
			if (end > this.source.size() - start) {
				end = this.source.size() - start;
			}*/
			
			if (end > this.source.size()) {
				end = this.source.size();
			}
			// end by
			
			data = this.source.subList(start, end);
		}
		return data;
	}

}
